﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity;
using DAL;

namespace BLL
{
    public class RoleService
    {
        private RolesDAL roleDAL = new RolesDAL();

        public void CreateRole(BoRoles role)
        {
            roleDAL.Insert(role);
        }

        public void UpdateRole(BoRoles role)
        {
            roleDAL.Update(role);
        }

        public int DeleteRole(BoRoles role)
        {
            BoRoles r = getRole(role.ROL_ID);
            if (r.ROL_TYPE == 0)
                return 0;//不允许删除系统用户
            else
            {
                roleDAL.Delete(role.ROL_ID);
                return 1;
            }
        }

        public BoRoles getRole(string id)
        {
            return roleDAL.GetModel(id);
        }

        public IList<BoRoles> getAllRoles()
        {
            return roleDAL.GetAllRoles();
        }

        /// <summary>
        /// 根据角色名称判断是否已经存在角色名称
        /// </summary>
        /// <param name="RoleName">角色名称</param>
        /// <returns>返回bool值</returns>
        public bool CheckRoleName(string RoleName)
        {
            return roleDAL.CheckRoleName(RoleName.Trim())>0;
        }

        public List<ModuleVo> getAuthorizedModules(string roleId)
        {
            RoleVo role = new RoleVo();
            role.RoleId = roleId;
            return role.getAuthorizedModules();
        }

        public void setRoleModules(RoleVo role, List<ModuleVo> modules)
        {
            role.RoleModules = modules;
            role.SaveRoleModules();
        }

    }
}
